//
//  WKCollectionViewController.m
//  WeKeTang
//
//  Created by ichina on 2017/8/24.
//  Copyright © 2017年 Dezhi Tiancheng Education Technology (Beijing) Co. Ltd. All rights reserved.
//

#import "WKCollectionViewController.h"
#import "WKCollectionCompleteCell.h"
#import "WKCollectionCell.h"
#import "WKEditorView.h"
#import "WKUniversal.h"
#import "WKLoginHandel.h"
#import "WKNetworkTools.h"
#import "WKCollectionCompleteModel.h"
#import "WKCollectionModel.h"
#import "WKAlerView.h"
#import "WKWebViewController.h"
#import "WKHomeViewController.h"

@interface WKCollectionViewController ()<UITableViewDelegate,UITableViewDataSource,WKEditorViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *lineView;
@property (weak, nonatomic) IBOutlet UIButton *btnCompleteCourse;
@property (weak, nonatomic) IBOutlet UIButton *btnSingleCourse;
@property (nonatomic, strong) UITableView *TBMain;
@property (nonatomic, strong) UIButton *btnRight;
@property (nonatomic, strong) YYLabel *footerLabel;
@property (nonatomic, strong) WKEditorView *editorView;
@property (nonatomic, strong) WKAlerView *alertView;
@property (nonatomic, strong) UIImageView *maskImgView;
@property (nonatomic, strong) NSArray *dataList;
@property (nonatomic, strong) NSMutableArray *deleteArr;
@property (nonatomic, assign) BOOL isComplete;
@property (nonatomic, assign) BOOL isSingle;
@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIView *rightView;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *leftUnView;
@property (nonatomic, strong) UIView *rightUnView;
@property (nonatomic, strong) UIView *bottomUnView;

@end

@implementation WKCollectionViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navItem.title = @"我的收藏";
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    
    self.deleteArr = [NSMutableArray array];
 NSLog(@"导航控制器：%lu",self.navigationController.viewControllers.count);
    [self setupUI];
}
- (void)setupUI{
    
    self.navgationBar.barTintColor = [UIColor whiteColor];
    //self.statusbar.backgroundColor = [UIColor blackColor];
    [self middleTitleColor:[UIColor blackColor]];
    self.navItem.leftBarButtonItem = nil;
    [self setLeftButtonWithImage:@"icon_return" highlightedImage:@"icon_return" target:self action:@selector(backAction)];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [self.navgationBar addSubview:self.btnRight];
    
    self.TBMain.editing = NO;
    self.TBMain = [[UITableView alloc]initWithFrame:CGRectMake(0, 115, kDeviceScreenWidth, kDeviceScreenHeight-115) style:UITableViewStylePlain];
    self.TBMain.delegate = self;
    self.TBMain.dataSource = self;
    [self.view addSubview:self.TBMain];
    
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kDeviceScreenWidth, 80)];
    self.footerLabel = [[YYLabel alloc]initWithFrame:CGRectMake(0, 0, kDeviceScreenWidth, 21)];
    self.footerLabel.center = footView.center;
    self.footerLabel.text = @"已加载全部内容";
    self.footerLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    self.footerLabel.textAlignment = NSTextAlignmentCenter;
    self.footerLabel.font = [UIFont systemFontOfSize:13];
    [footView addSubview:self.footerLabel];
    
    self.TBMain.tableFooterView = footView;
    
    self.editorView = [[WKEditorView alloc]initWithFrame:CGRectMake(0, kDeviceScreenHeight, kDeviceScreenWidth, 70)];
    self.editorView.backgroundColor = RGBColor(245, 245, 245);
    self.editorView.delegate = self;
    [self.view addSubview:self.editorView];
    
    //默认选中整套课程
    [self btnCompleteCourseAction:nil];
    //加占位图
    self.maskImgView = [[UIImageView alloc]initWithFrame:CGRectMake((kDeviceScreenWidth - 115)*0.5, (kDeviceScreenHeight - 120)*0.5, 115, 120)];
    self.maskImgView.image = [UIImage imageNamed:@"icon_collectioncourse"];
    self.maskImgView.hidden = YES;
    [self.view addSubview:self.maskImgView];

}
#pragma mark - 整套课程
- (IBAction)btnCompleteCourseAction:(UIButton *)sender {
    self.TBMain.editing = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    [self loadComoleteData];
    _isComplete = YES;
    _isSingle = NO;
    sender.backgroundColor = [UIColor whiteColor];
    self.btnSingleCourse.backgroundColor = [UIColor colorWithHexString:@"#f4f4f4"];
    [self.leftView removeFromSuperview];
    [self.bottomView removeFromSuperview];
    [self.rightView removeFromSuperview];
    [self.leftUnView removeFromSuperview];
    [self.bottomUnView removeFromSuperview];
    [self.rightUnView removeFromSuperview];
    
    self.leftView = [[UIView alloc]init];
    self.leftView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.leftView.frame = CGRectMake(self.btnSingleCourse.left, self.btnSingleCourse.top, 0.5, self.btnSingleCourse.height);
    [self.view addSubview:self.leftView];
    self.bottomView = [[UIView alloc]init];
    self.bottomView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.bottomView.frame = CGRectMake(self.btnSingleCourse.left, self.btnSingleCourse.bottom, self.btnSingleCourse.width, 0.5);
    [self.view addSubview:self.bottomView];
    self.rightView = [[UIView alloc]init];
    self.rightView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.rightView.frame = CGRectMake(self.btnSingleCourse.right, self.btnSingleCourse.top, 0.5, self.btnSingleCourse.height);
    [self.view addSubview:self.rightView];
    
     [self.TBMain registerClass:[WKCollectionCompleteCell class] forCellReuseIdentifier:@"completeCell"];
    
//    [self.TBMain reloadData];
}
- (void)backAction{
    [super backAction];
    
    if (self.block) {
        self.block();
    }
}
#pragma mark - 单个课程
- (IBAction)btnSingleCourseAction:(UIButton *)sender {
    self.TBMain.editing = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    [self loadSingleData];
    _isComplete = NO;
    _isSingle = YES;
     [self.TBMain registerClass:[WKCollectionCell class] forCellReuseIdentifier:@"collectionCell"];
    sender.backgroundColor = [UIColor whiteColor];
    self.btnCompleteCourse.backgroundColor = [UIColor colorWithHexString:@"#f4f4f4"];
    [self.leftUnView removeFromSuperview];
    [self.bottomUnView removeFromSuperview];
    [self.rightUnView removeFromSuperview];
    [self.leftView removeFromSuperview];
    [self.bottomView removeFromSuperview];
    [self.rightView removeFromSuperview];
    self.leftUnView = [[UIView alloc]init];
    self.leftUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.leftUnView.frame = CGRectMake(self.btnCompleteCourse.left, self.btnCompleteCourse.top, 0.5, self.btnCompleteCourse.height);
    [self.view addSubview:self.leftUnView];
    self.bottomUnView = [[UIView alloc]init];
    self.bottomUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.bottomUnView.frame = CGRectMake(self.btnCompleteCourse.left, self.btnCompleteCourse.bottom, self.btnCompleteCourse.width, 0.5);
    [self.view addSubview:self.bottomUnView];
    self.rightUnView = [[UIView alloc]init];
    self.rightUnView.backgroundColor = [UIColor colorWithHexString:@"#e0e0e0"];
    self.rightUnView.frame = CGRectMake(self.btnCompleteCourse.right, self.btnCompleteCourse.top, 0.5, self.btnCompleteCourse.height);
    [self.view addSubview:self.rightUnView];
//    [self.TBMain reloadData];
}
#pragma mark - 获取整个课程数据
- (void)loadComoleteData{
    
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSString *mac = [WKUniversal macaddress];
    NSString *phpsessid = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"collectinfo" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:mac forKey:@"mac"];
    [para setObject:phpsessid forKey:@"phpsessid"];
    
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:nil completionHandler:^(id responseObject) {
    } errorHandler:^(NSError *error) {
         [weakSelf showCustomAlertMessage:@"网络错误"];
    } finishHandler:^(id responseObject) {
        //NSLog(@"整个收藏%@",responseObject);
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSDictionary *head = dict[@"head"];
        NSDictionary *body = dict[@"body"];
        NSArray *pack = body[@"pack"];
        NSString *statuscode = head[@"statuscode"];
        if ([statuscode intValue] == 100) {
            NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:pack.count];
            for (NSInteger i = 0 ; i<pack.count; i++) {
                WKCollectionCompleteModel *model = [WKCollectionCompleteModel mj_objectWithKeyValues:pack[i]];
                [mArray addObject:model];
            }
            weakSelf.dataList = mArray.mutableCopy;
            if (weakSelf.dataList.count == 0) {
                //加占位图
                self.maskImgView.hidden = NO;
                self.footerLabel.hidden = YES;
            }else{
                self.maskImgView.hidden = YES;
                self.footerLabel.hidden = NO;
            }
            [weakSelf.TBMain reloadData];
//            NSLog(@"收藏%ld",weakSelf.dataList.count);
        }else{
            //[weakSelf showCustomAlertMessage:@"网络错误"];
        }
    }];
    
}
#pragma mark - 获取单个课程数据
- (void)loadSingleData{
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSString *mac = [WKUniversal macaddress];
    NSString *phpsessid = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"collectinfo" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:mac forKey:@"mac"];
    [para setObject:phpsessid forKey:@"phpsessid"];
    [[WKNetworkTools shareManger]RunNoneRequest:para path:kServerDomain tip:nil completionHandler:^(id responseObject) {
    } errorHandler:^(NSError *error) {
        [weakSelf showCustomAlertMessage:@"网络错误"];
    } finishHandler:^(id responseObject) {
        NSLog(@"单个收藏%@",responseObject);
        NSDictionary *dict = [responseObject mj_JSONObject];
        NSDictionary *head = dict[@"head"];
        NSDictionary *body = dict[@"body"];
        NSArray *course = body[@"course"];
        NSString *statuscode = head[@"statuscode"];
        if ([statuscode intValue] == 100) {
            NSMutableArray *mArray = [NSMutableArray arrayWithCapacity:course.count];
            for (NSInteger i = 0 ; i<course.count; i++) {
                WKCollectionModel *model = [WKCollectionModel mj_objectWithKeyValues:course[i]];
                [mArray addObject:model];
            }
            weakSelf.dataList = mArray.mutableCopy;
            if (weakSelf.dataList.count == 0) {
                //加占位图
                self.maskImgView.hidden = NO;
                self.footerLabel.hidden = YES;
            }else{
                self.maskImgView.hidden = YES;
                self.footerLabel.hidden = NO;
            }
            [weakSelf.TBMain reloadData];
//            NSLog(@"收藏%ld",weakSelf.dataList.count);
        }else{
            //[weakSelf showCustomAlertMessage:@"网络错误"];
        }
    }];

    
}

#pragma mark - 编辑
- (void)rightBtnCollentionAction:(UIButton*)sender{
    
    self.TBMain.allowsMultipleSelectionDuringEditing = YES;
    self.TBMain.editing = !self.TBMain.editing;
    
    if (self.TBMain.editing){
        [self.btnRight setTitle:@"取消" forState:UIControlStateNormal];
        [self.btnRight setImage:nil forState:UIControlStateNormal];
         NSLog(@"----------%ld",self.deleteArr.count);
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }else{
            [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
        }
        [self showEditorView];
        
    }else{
        [_btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
        [self.btnRight setTitle:nil forState:UIControlStateNormal];
        self.editorView.btnSelectAll.selected = NO;
        [self.deleteArr removeObjectsInArray:self.dataList];
        NSLog(@"单选：%ld",self.deleteArr.count);
        [self dismissEditorView];
    }
}

#pragma mark - WKEditorViewDelegate
-(void)WKEditorView:(WKEditorView *)wkEditorView btnSelectAllAction:(UIButton *)sender{

    sender.selected =! sender.selected;
    if (sender.selected) {
        [sender setTitle:@"取消全选" forState:UIControlStateSelected];
         [self.deleteArr removeObjectsInArray:self.dataList];
        for (int i = 0; i < self.dataList.count; i ++) {
            
            NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
            [self.TBMain selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
        }
        [self.deleteArr addObjectsFromArray:self.dataList];
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }
        NSLog(@"全选：%ld",self.deleteArr.count);

    }else{
        //取消全选
        [sender setTitle:@"全选" forState:UIControlStateNormal];
        
        [self.deleteArr removeObjectsInArray:self.dataList];
         NSLog(@"全选：%ld",self.deleteArr.count);
        
        [self rightBtnCollentionAction:nil];
    }

}

#pragma mark - 全部删除
-(void)WKEditorView:(WKEditorView *)wkEditorView btnDeleteAction:(UIButton *)sender{
    
    if (self.deleteArr.count == 0 && self.dataList.count == 0) {
        [self showCustomAlertMessage:@"请选择条目!"];
        return;
    }else if (self.deleteArr.count == 0){
        [self showCustomAlertMessage:@"请选择要删除的内容!"];
        return;
        
    }
    
  __weak typeof(self) weakSelf = self;
    //弹框
    self.alertView = [[WKAlerView alloc]initWithFrame:[UIScreen mainScreen].bounds message:@"确定要删除这些数据？" tip:nil title1:@"确定" title2:@"取消"];
    self.alertView.confirmBlock = ^{
        //执行删除操作
        [weakSelf deleteCollectionCourse];
       [weakSelf.alertView removeFromSuperview];
    };
    self.alertView.cancelBlock = ^{
        [weakSelf cancelDelegateWatchData];
        [weakSelf.alertView removeFromSuperview];
    };
    self.alertView.deleteBlock = ^{
        [weakSelf cancelDelegateWatchData];
        [weakSelf.alertView removeFromSuperview];
    };
    [[UIApplication sharedApplication].keyWindow addSubview:self.alertView];
    
    [self dismissEditorView];
}
#pragma mark - 确定删除
- (void)deleteCollectionCourse{
    __weak typeof(self) weakSelf = self;
    
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    NSString *mac = [WKUniversal macaddress];
    NSString *phpsessid = [WKLoginHandel getLoginDataWithString:@"SESSID"];
    NSMutableDictionary *para = [NSMutableDictionary dictionary];
    [para setObject:@"delcollect" forKey:@"commandid"];
    [para setObject:userid forKey:@"userid"];
    [para setObject:mac forKey:@"mac"];
    [para setObject:phpsessid forKey:@"phpsessid"];
    
    if (_isComplete) {
        [para setObject:@"2" forKey:@"ctype"];
    }else if (_isSingle){
        [para setObject:@"1" forKey:@"ctype"];
    }
    NSMutableString *str = [NSMutableString string];
    if (_isComplete) {
//        NSLog(@"要删除的整个课程数据：%@",self.deleteArr);
        for (NSInteger i = 0; i<self.deleteArr.count; i++) {
            WKCollectionCompleteModel *model = self.deleteArr[i];
            [str appendFormat:@"%@", model.pack_id];
            [str appendString:@","];
            
        }
        [str deleteCharactersInRange:NSMakeRange(str.length -1, 1)];
//        NSLog(@"要删除的整个cids：%@",str);
    }else if (_isSingle){
//        NSLog(@"要删除的单个课程数据：%@",self.deleteArr);
        for (NSInteger i = 0; i<self.deleteArr.count; i++) {
            WKCollectionModel *model = self.deleteArr[i];
//            NSLog(@"打印单个cids：%@",model.section_id);
            [str appendString:model.section_id];
            [str appendString:@","];
        }
       
        [str deleteCharactersInRange:NSMakeRange(str.length -1, 1)];
//         NSLog(@"要删除的单个cids：%@",str);
    }
    
    [para setObject:str forKey:@"cids"];
//     NSLog(@"para----------------------:%@",para);
    [[WKNetworkTools shareManger]setHttpMethod:@"POST"];
    [[WKNetworkTools shareManger]RunRequest:para path:kServerDomain completionHandler:^(id responseObject) {
        
    } errorHandler:^(NSError *error) {
        
    } finishHandler:^(id responseObject) {
        NSDictionary *dict = [responseObject mj_JSONObject];
       // NSLog(@"删除收藏%@",responseObject);
        NSDictionary *head = dict[@"head"];
        NSString *statuscode = head[@"statuscode"];
        if ([statuscode intValue] == 100) {
            weakSelf.TBMain.editing = NO;
            [_btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
            [self.btnRight setTitle:nil forState:UIControlStateNormal];
            if (_isComplete) {
                [weakSelf loadComoleteData];
            }else if (_isSingle){
                [weakSelf loadSingleData];
            }
            [weakSelf showCustomAlertMessage:@"删除成功"];
            [weakSelf.deleteArr removeAllObjects];
            [weakSelf.TBMain reloadData];
        }
    }];
    
}
- (void)cancelDelegateWatchData{
    
    self.TBMain.editing = NO;
    [self.btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
    [self.btnRight setTitle:nil forState:UIControlStateNormal];
    self.editorView.btnSelectAll.selected = NO;
    [self dismissEditorView];
    [self.editorView.btnDelete setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteArr removeAllObjects];
    [self.alertView removeFromSuperview];
}
#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (_isComplete) {
        static NSString *cellIdentifier = @"completeCell";
        WKCollectionCompleteCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
            cell = [[WKCollectionCompleteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
        cell.selectedBackgroundView = [[UIView alloc]init];
        cell.tintColor = [UIColor lightGrayColor];// 改变编辑状态左侧勾选颜色
        cell.model = self.dataList[indexPath.row];
        
        return cell;
    }
    
    static NSString *cellID =  @"collectionCell";
    WKCollectionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        
        cell = [[WKCollectionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectedBackgroundView = [[UIView alloc]init];
    cell.tintColor = [UIColor lightGrayColor];// 改变编辑状态左侧勾选颜色
    cell.model = self.dataList[indexPath.row];
    
    return cell;
}
#pragma mark - tableView代理方法
//是否可以编辑  默认的时YES
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

//选择编辑的方式,按照选择的方式对表进行处理
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
    }
    
}
//选择你要对表进行处理的方式  默认是删除方式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

//选中时将选中行的在self.dataArray 中的数据添加到删除数组self.deleteArr中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    __weak typeof(self) weakSelf = self;
    NSString *userid = [WKLoginHandel getLoginDataWithString:@"userid"];
    if (tableView.editing) {
        
        [self.deleteArr addObject:[self.dataList objectAtIndex:indexPath.row]];
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",(unsigned long)self.deleteArr.count] forState:UIControlStateNormal];
        }

        NSLog(@"单选：%ld",self.deleteArr.count);
    }else{
        if (_isComplete) {
            WKCollectionCompleteCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            cell.model = self.dataList[indexPath.row];
            NSLog(@"-----------%@-----------%@",cell.model.pack_grade,cell.model.pack_type);
            NSString *urlStr;
            //专题
            if ([cell.model.pack_grade isEqualToString:@"1036"]||[cell.model.pack_type isEqualToString:@"6"]) {
                
                urlStr = [NSString stringWithFormat:@"%@/andriodwk/xx-chapter/packid/%@/userid/%@",kTestMainUrl,cell.model.pack_id,userid];
                
            }else{
                //整套
                urlStr = [NSString stringWithFormat:@"%@/andriodwk/chapter/packid/%@/userid/%@",kTestMainUrl,cell.model.pack_id,userid];
            }
            WKHomeViewController *homeVC = [[WKHomeViewController alloc]init];
            homeVC.collectionBlock = ^{
                [weakSelf loadComoleteData];
                [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
            };
            homeVC.isCollection = YES;
            homeVC.urlStr = urlStr;
            homeVC.userId = userid;
            [self.navigationController pushViewController:homeVC animated:YES];
            NSLog(@"整套课程地址：%@",urlStr);
        }else if (_isSingle){
            
            WKCollectionCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            cell.model = self.dataList[indexPath.row];
             NSString *urlStr = [NSString stringWithFormat:@"%@/andriodwk/course/courseid/%@/userid/%@",kTestMainUrl,cell.model.section_id,userid];
            NSLog(@"单个课程地址：%@",urlStr);
            WKHomeViewController *homeVC = [[WKHomeViewController alloc]init];
            homeVC.collectionBlock = ^{
                [weakSelf loadSingleData];
            };
            homeVC.isCollection = YES;
            homeVC.urlStr = urlStr;
            homeVC.userId = userid;
            [self.navigationController pushViewController:homeVC animated:YES];
            
        }
    }
}
//取消选中时 将存放在self.deleteArr中的数据移除
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath  {
    
    if (tableView.editing) {
        [self.deleteArr removeObject:[self.dataList objectAtIndex:indexPath.row]];
        if (self.deleteArr.count != 0) {
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除(%ld)",self.deleteArr.count] forState:UIControlStateNormal];
        }else{
            [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除"] forState:UIControlStateNormal];
        }
        NSLog(@"单选：%ld",self.deleteArr.count);
    }else{
        
//        [self showCustomAlertMessage:@"点击播放"];
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        return 120;
}

- (void)showEditorView{
    [self.editorView.btnDelete setTitle:[NSString stringWithFormat:@"删除"] forState:UIControlStateNormal];
    [UIView animateWithDuration:0.2 animations:^{
        self.editorView.frame = CGRectMake(0, kDeviceScreenHeight - 70, kDeviceScreenWidth, 70);
    }];
}
- (void)dismissEditorView{
    
    [UIView animateWithDuration:0.2 animations:^{
        self.editorView.frame = CGRectMake(0, kDeviceScreenHeight, kDeviceScreenWidth, 70);
    }];
}
- (UIButton *)btnRight{
    
    if (_btnRight == nil) {
        _btnRight = [UIButton  buttonWithType:UIButtonTypeCustom];
        _btnRight.frame = CGRectMake(kDeviceScreenWidth - 40, (44-35)*0.5, 35,35);
        [_btnRight setImage:IMG(@"icon_edtiorImg") forState:UIControlStateNormal];
        [_btnRight setTitleColor:RGBColor(40, 188, 203) forState:UIControlStateNormal];
        _btnRight.titleLabel.font = [UIFont systemFontOfSize:15];
        [_btnRight addTarget:self action:@selector(rightBtnCollentionAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnRight;
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.leftView.frame = CGRectMake(self.btnCompleteCourse.left, self.btnCompleteCourse.top, 0.5, self.btnCompleteCourse.height);
    self.bottomView.frame = CGRectMake(self.btnCompleteCourse.left, self.btnCompleteCourse.bottom, self.btnCompleteCourse.width, 0.5);
    self.rightView.frame = CGRectMake(self.btnCompleteCourse.right, self.btnCompleteCourse.top, 0.5, self.btnCompleteCourse.height);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
